<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>命令模式</title>
</head>

<body>
    <script>
        // 命令模式

        // 发布者
        // 接收者
        // 命令对象

        // 接收类
        class Receiver {
            execute() {
                console.log("接收者执行请求");
            }
        }
        // 命令对象
        class Command {
            constructor(receiver) {
                this.receiver = receiver
            }
            execute() {
                console.log("命令对象==>接收者==>对应接口执行");
                this.receiver.execute()
            }
        }
        // 发布者
        class Invoker{
            constructor(command){
                this.command = command
            }
            invoker(){
                console.log("发布者发送请求");
                this.command.execute()
            }
        }
        var r = new Receiver()
        var c = new Command(r)
        var i = new Invoker(c)
        i.invoker()



</script>
</body>

</html>